﻿using System.Runtime.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NazTek.Extension.Clr4.Test
{
    /// <summary>
    /// Contains Unit Tests for ObjectExtension class public members
    /// </summary>
    [TestClass()]
    public class ObjectExtensionTest
    {
        private TestContext testContextInstance;
        /// <summary>
        /// Name of object value stored in property bag
        /// </summary>
        private const string MOCK_OBJECT_INSTANCE_NAME = "MockPerson";
        /// <summary>
        /// Gets/Sets current test context, e.g., property bag
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
                testContextInstance.Properties.Add(MOCK_OBJECT_INSTANCE_NAME, new MockPerson());
            }
        }
        /// <summary>
        /// Attempt to serialize an object not marked serializable, exception expected
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(SerializationException))]
        public void TestToString_NonserializableObject()
        {
            string actual = new MockNonserializablePerson().ToString(FormatOption.Base32Binary);
        }
        /// <summary>
        /// Tests base 32 binary serialization
        /// </summary>
        [TestMethod()]
        public void TestToString_Base32Binary()
        {
            string expected = MockData.SERIAL_BASE32_BINARY_MOCK_PERSON;
            string actual = testContextInstance.Properties[MOCK_OBJECT_INSTANCE_NAME].ToString(FormatOption.Base32Binary);
            Assert.AreEqual<string>(expected, actual);
        }
        /// <summary>
        /// Tests base 32 soap serialization
        ///</summary>
        [TestMethod()]
        public void TestToString_Base32Soap()
        {
            string expected = MockData.SERIAL_BASE32_SOAP_MOCK_PERSON;
            string actual = testContextInstance.Properties[MOCK_OBJECT_INSTANCE_NAME].ToString(FormatOption.Base32Soap);
            Assert.AreEqual<string>(expected, actual);
        }
        /// <summary>
        /// Tests base 64 binary serialization
        ///</summary>
        [TestMethod()]
        public void TestToString_Base64Binary()
        {
            string expected = MockData.SERIAL_BASE64_BINARY_MOCK_PERSON;
            string actual = testContextInstance.Properties[MOCK_OBJECT_INSTANCE_NAME].ToString(FormatOption.Base64Binary);
            Assert.AreEqual<string>(expected, actual);
        }
        /// <summary>
        /// Tests base 64 soap serialization
        ///</summary>
        [TestMethod()]
        public void TestToString_Base64Soap()
        {
            string expected = MockData.SERIAL_BASE64_SOAP_MOCK_PERSON;
            string actual = testContextInstance.Properties[MOCK_OBJECT_INSTANCE_NAME].ToString(FormatOption.Base64Soap);
            Assert.AreEqual<string>(expected, actual);
        }
        /// <summary>
        /// Tests pox serialization
        ///</summary>
        [TestMethod()]
        public void TestToString_Pox()
        {
            string expected = MockData.SERIAL_POX_MOCK_PERSON;
            string actual = testContextInstance.Properties[MOCK_OBJECT_INSTANCE_NAME].ToString(FormatOption.Pox);
            Assert.AreEqual<string>(expected, actual);
        }
        /// <summary>
        /// Tests CopyTo with null target
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(System.ArgumentNullException))]
        public void TestCopyTo_NullTarget()
        {
            new MockPerson().CopyTo(null);
        }
        /// <summary>
        /// Tests CopyTo
        ///</summary>
        [TestMethod()]
        public void TestCopyTo()
        {
            MockSenior person = new MockSenior();
            new MockPerson() { Name = "Bill" }.CopyTo(person);
            Assert.IsTrue(person.Equals(new MockPerson() { Name = "Bill" }));
        }
    }
}